<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>字符串右移</title>
<!--autor: carriehuang | QQ:453555909 | 转载需注明原处-->
<head>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .wrap{
            width:1200px;
            height:420px;
            margin: 0 auto;
            font-size: 14px;
            border: 10px solid #c4c4c4;
            padding: 10px;
            position: relative;
        }
        .txt-con{
            width:500px;
            height:400px;
            border: 1px dashed #c4c4c4;
            padding: 10px;
        }
        .txt-left{
            float: left;
            background-color: #faf2cc;
        }
        .txt-right{
            float: left;
            background-color: #00ffff;
        }
        .txt-center{
            width:115px;
            height:400px;
            float: left;
            margin: 20px;
            text-align: center;
        }
        .txt-center a{
            color: #fff;
            display: block;
            width: 100%;
            padding: 10px 0;
            text-decoration: none;
            background-color: #ce8483;
        }
        .txt-center p{
            font-size: 20px;
            margin-top: 30px;
        }
        .txt-center ul{
            width: 96px;
            margin: 30px auto 0;
            text-align: center;
        }
        .txt-center ul li{
            list-style: none;
            width: 10px;
            height: 10px;
            float: left;
            margin-left: 2px;
            background-color: #f4c414;
        }
        .txt-center ul li.cur{
            background-color: #fc5421;
        }
    </style>
</head>
<body>
<div class="wrap">
    <textarea value="" name="import" class="txt-con txt-left" ></textarea>
    <div class="txt-center">
        <a href="javascript:;" id="j_to_right" >把文字右移</a>
        <p id="j_total">0/0</p>
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="txt-con txt-right" ></div>
</div>


<script type="text/javascript">

    window.onload=function(){
        var oTotal = document.getElementById("j_total");
        var oToRight = document.getElementById("j_to_right");
        var aTxtCon = document.getElementsByClassName("txt-con");
        var aLi = document.getElementsByTagName("li");
        var timer = null;
        var i=1;
        var index=0;
        oToRight.onclick = function(){
            clearInterval(timer);
            var len = (aTxtCon[0].value).length;
            var txt = aTxtCon[0].value;
            timer = setInterval(function(){
                pass(len,txt);
            },150);
        };

        function pass(num,t){
            if(i<=num){
                aTxtCon[1].innerHTML = t.slice(0,i);
                aTxtCon[0].value = t.slice(i,-1);
                oTotal.innerHTML = (aTxtCon[1].innerHTML).length+"/"+num;
                i++;
            }else{

                clearInterval(timer);
            }

            for(var j=0;j<aLi.length;j++){
                aLi[j].className="";
            }
            if(index<aLi.length){
                aLi[index].className="cur";
                index++;
            }else{
                index =0;
            }


        }

    }
</script>
</body>

</html>
